package com.example.controller;

import com.example.common.Result;
import com.example.entity.Ordermsg;
import com.example.service.OrdermsgService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 订单(Ordermsg)表控制层
 *
 */
@RestController
public class OrdermsgController {
    @Resource
    private OrdermsgService ordermsgService;

    //信息列表
    @ResponseBody
    @RequestMapping("ordermsgList")
    public Result ordermsgList(@RequestParam(defaultValue = "1", value = "pageNum") Integer pageNum, 
                              @RequestParam(defaultValue = "1", value = "pageSize") Integer pageSize, 
                              HttpServletRequest request) {
        String key = request.getParameter("key");
        String key1 = request.getParameter("key1");
        String memberid = request.getParameter("memberid");
        
        PageInfo<Ordermsg> pageInfo = ordermsgService.getOrdermsgList(pageNum, pageSize, key, key1, memberid);
        return Result.success(pageInfo);
    }

    //添加订单
    @ResponseBody
    @RequestMapping("ordermsgAdd")
    public Result ordermsgAdd(Ordermsg ordermsg, HttpServletRequest request) {
        String vals = request.getParameter("vals");
        ordermsgService.addOrdermsg(ordermsg, vals);
        return Result.success();
    }

    //发货处理
    @ResponseBody
    @RequestMapping("ordermsgFh")
    public Result ordermsgFh(Ordermsg ordermsg, HttpServletRequest request) {
        ordermsgService.shipOrder(ordermsg);
        return Result.success();
    }

    //确认收货
    @ResponseBody
    @RequestMapping("ordermsgQrsh")
    public Result ordermsgQrsh(Ordermsg ordermsg, HttpServletRequest request) {
        ordermsgService.confirmOrder(ordermsg);
        return Result.success();
    }

    //删除信息
    @ResponseBody
    @RequestMapping("ordermsgDel")
    public Result ordermsgDel(int id, HttpServletRequest request) {
        ordermsgService.deleteOrdermsg(id);
        return Result.success();
    }

    //批量删除信息
    @ResponseBody
    @RequestMapping("ordermsgDeleteAll")
    public Result typeDeleteAll(HttpServletRequest request) {
        String vals = request.getParameter("vals");
        ordermsgService.batchDeleteOrdermsg(vals);
        return Result.success();
    }
    
    //销售统计
    @ResponseBody
    @RequestMapping("ordermsgTj")
    public Result ordermsgTj(HttpServletRequest request) {
        String status = request.getParameter("status");
        List<Ordermsg> list = ordermsgService.getSalesStatistics(status);
        return Result.success(list);
    }
}

